package org.github.core.base;

import java.util.List;
import lombok.val;
import org.springframework.transaction.annotation.Transactional;
import static cn.hutool.core.collection.ListUtil.partition;

public interface MbpService<T> extends com.baomidou.mybatisplus.extension.service.IService<T>, IService {
  @Transactional(rollbackFor = Exception.class)
  default int insertBatch(List<T> list) {
    val mapper    = ((MbpMapper<T>) getBaseMapper());
    val partition = partition(list, DEFAULT_BATCH_SIZE);
    return partition.stream().mapToInt(mapper::insertBatchSomeColumn).sum();
  }
}
